import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { BaseItemNormal } from "../common/item/BaseItemNormal";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { ItemInfo } from "../../resource/info/ItemInfo";
import { DataEvent } from "../../events/DataEvent";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { Cache } from "../../cache/Cache";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class HandinMaterialRenderer
    
    export  class HandinMaterialRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            this._baseItem = new BaseItemNormal();
            this._baseItem.setSize(32, 32);
            this._baseItem.x = 5;
            this._baseItem.y = 5;
            this._baseItem.isShowLock = false;
            this.addChild(this._baseItem);
            this._nameLabel = ObjCreate.createLabel("", 45, 0, 200, 20, flash.text.TextFormatAlign.LEFT, this, true);
            this._nameLabel.drawNow();
            this._descLabel = ObjCreate.createLabel("", 45, 20, 200, 20, flash.text.TextFormatAlign.LEFT, this, true);
            this._descLabel.textField.multiline = true;
            this._descLabel.textField.wordWrap = true;
            this._descLabel.textField.mouseWheelEnabled = false;
            this._descLabel.drawNow();
            this._ownLabel = ObjCreate.createLabel("", 150, 0, 150, 20, flash.text.TextFormatAlign.LEFT, this, true);
            this._ownLabel.drawNow();
            this._optBtn = ObjCreate.createGButton(Language.getString(69802), 250, 10, 49, 26, this, "ButtonSpecial");
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._optBtn.drawNow();
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (data) 
            {
                loc1 = data as ItemInfo;
                this.dispatchEvent(new DataEvent(GModuleEvent.HandinMaterial, new ItemData(loc1.item.code), false, true, true));
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            super.data = arg1;
            if (data) 
            {
                loc1 = data as ItemInfo;
                loc2 = new ItemData(loc1.item.code);
                this._baseItem.itemData = loc2;
                this._nameLabel.htmlText = ItemsUtil.getItemName(loc2);
                this._descLabel.htmlText = loc2.itemInfo.item.descStr;
                loc3 = this.getOwnNum(loc2);
                this._ownLabel.htmlText = Language.getStringByParam(69803, loc3);
            }
            return;
        }

        /* internal  */getOwnNum(arg1: ItemData): int
        {
            var loc3=null;
            var loc1=0;
            var loc2=Cache.instance.pack.backPackCache.getPropItems();
            var loc4=0;
            var loc5=loc2;
            for(loc3 of loc5) 
            {
                if (!(loc3.itemCode == arg1.itemCode || loc3.itemCode == arg1.itemInfo.item.codeUnbind)) 
                {
                    continue;
                }
                loc1 = loc1 + loc3.itemAmount;
            }
            return loc1;
        }

        /* internal */ /* var */_baseItem: BaseItemNormal;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_descLabel: GLabel;

        /* internal */ /* var */_ownLabel: GLabel;

        /* internal */ /* var */_optBtn: GButton;
    }
